import { post, get } from '../../../utils/request';

const addDataSource = data => post('mgt/save/dataSourceconfig', data);

const editDataSource = data => post('mgt/add/dataSourceconfig', data);

const dataDetail = data => post('mgt/query/dataSourceconfigDetail', data);

const testConnect = data => post('mgt/test/connection', data);

const orgList = data => get('mgt/4A/getRootTree', data);

// todo 智搜推送 用到而已 （后端：原来的实现方法为空）
const targetQueryByName = ({ content }) =>
  get('mgt/idaas/getIDaaSFuzzySearch', {
    content: content || ''
  });

// todo 智搜推送 用到而已
// 按组织查询(目标、使用对象)
const targetQueryByOrg = ({ orgCode, pageNum = 1, pageSize = 5 }) =>
  get('mgt/idaas/getIDaaSPushPerson', {
    orgCode,
    pageNo: String(pageNum),
    pageSize: String(pageSize)
  });

// 标签列表--查看用户标签弹出窗列表
const queryUserLabel = ({ content, userLabel, pageNum = 1, pageSize = 5 }) =>
  post('mgt/label/queryUserLabel', {
    userLabel: userLabel || [],
    content: content || '',
    pageNum: String(pageNum),
    pageSize: String(pageSize)
  });

// 标签列表--新增用户弹出窗列表、使用对象
const queryLabelByName = ({ content, orgCode, pageNum = 1, pageSize = 5 }) =>
  post('mgt/label/addUserLabel', {
    orgCode: orgCode || '',
    content: content || '',
    pageNum: String(pageNum),
    pageSize: String(pageSize)
  });

const queryByName = ({ content, orgCode, pageNum = 1, pageSize = 5 }) =>
  post('mgt/authority/fuzzySearch', {
    content,
    orgCode,
    pageNum: String(pageNum),
    pageSize: String(pageSize)
  });

// 按组织查询
const queryByOrg = ({ orgCode, userName, pageNum = 1, pageSize = 5 }) =>
  get('mgt/4A/authority/orgUser', {
    orgCode,
    userName,
    pageNum: String(pageNum),
    pageSize: String(pageSize)
  });

export default {
  addDataSource,
  targetQueryByName,
  targetQueryByOrg,
  editDataSource,
  dataDetail,
  testConnect,
  orgList,
  queryByOrg,
  queryByName,
  queryLabelByName,
  queryUserLabel
};
